package nc.plugin;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Vector;
import java.util.concurrent.ConcurrentHashMap;

import javax.naming.NamingException;

import nc.bs.dao.BaseDAO;
import nc.bs.dao.DAOException;
import nc.bs.framework.common.InvocationInfoProxy;
import nc.bs.framework.common.NCLocator;
import nc.bs.gl.pfxx.GLPluginUtils;
import nc.bs.gl.pubinterface.IVoucherDelete;
import nc.bs.gl.pubinterface.IVoucherSave;
import nc.bs.gl.voucher.VoucherCheckBO;
import nc.bs.glcom.ass.assitem.cache.AccAssItemCache;
import nc.bs.logging.Logger;
import nc.bs.ml.NCLangResOnserver;
import nc.bs.pfxx.ISwapContext;
import nc.bs.pfxx.plugin.AbstractPfxxPlugin;
import nc.bs.pub.SystemException;
import nc.bs.sscrp.rpbill.util.RPBillConvertUtil;
import nc.bs.uap.lock.PKLock;
import nc.bs.voucher.pub.util.VoucherBillUtil;
import nc.impl.gl.lightgl.voucherbill.VoucherBillSaveValidate;
import nc.itf.gl.pub.GLStartCheckUtil;
import nc.itf.gl.pub.IFreevaluePub;
import nc.bs.gl.voucher.VoucherCheckBO;
import nc.itf.gl.voucher.IVoucher;
import nc.itf.gl.voucher.IVoucherList;
import nc.itf.gl.voucher.IVoucherTally;
import nc.itf.glcom.para.IGlPara;
import nc.itf.uap.pf.IplatFormEntry;
import nc.jdbc.framework.SQLParameter;
import nc.jdbc.framework.processor.ColumnListProcessor;
import nc.jdbc.framework.processor.ColumnProcessor;
import nc.jdbc.framework.processor.ResultSetProcessor;
import nc.pubitf.accperiod.AccountCalendar;
import nc.pubitf.bd.accessor.GeneralAccessorFactory;
import nc.pubitf.bd.accessor.IGeneralAccessor;
import nc.pubitf.org.IBusiFuncQryPubService;
import nc.pubitf.org.IOrgRelationDataPubService;
import nc.pubitf.org.cache.IBasicOrgUnitPubService_C;
import nc.vo.bd.accessor.IBDData;
import nc.vo.bd.accessor.bankaccsub.BankaccsubBDDataVO;
import nc.vo.bd.account.AccAssVO;
import nc.vo.bd.account.AccountVO;
import nc.vo.fipub.freevalue.GlAssVO;
import nc.vo.fipub.freevalue.Module;
import nc.vo.fipub.rulecheck.RuleQueryVO;
import nc.vo.gateway60.accountbook.AccountBookUtil;
import nc.vo.gateway60.itfs.AccountUtilGL;
import nc.vo.gateway60.itfs.CalendarUtilGL;
import nc.vo.gateway60.itfs.Currency;
import nc.vo.gateway60.pub.GlBusinessException;
import nc.vo.gateway60.pub.ReturnObjException;
import nc.vo.gl.pubinterface.VoucherOperateInterfaceVO;
import nc.vo.gl.pubinterface.VoucherSaveInterfaceVO;
import nc.vo.gl.pubvoucher.DetailVO;
import nc.vo.gl.pubvoucher.GLParameterVO;
import nc.vo.gl.pubvoucher.OperationResultVO;
import nc.vo.gl.pubvoucher.VoucherVO;
import nc.vo.gl.voucher.TallyConditionVO;
import nc.vo.gl.voucher.VoucherCheckMessage;
import nc.vo.gl.voucherbill.GLVoucherAggVO;
import nc.vo.gl.voucherbill.GLVoucherVO;
import nc.vo.gl.voucherbill.VoucherDetailVO;
import nc.vo.glcom.ass.AssVO;
import nc.vo.glcom.exception.GLBusinessException;
import nc.vo.glcom.tools.GLPubProxy;
import nc.vo.jcom.lang.StringUtil;
import nc.vo.ml.NCLangRes4VoTransl;
import nc.vo.pf.change.PfUtilBaseTools;
import nc.vo.pfxx.auxiliary.AggxsysregisterVO;
import nc.vo.pfxx.idcontrast.IDContrastVO;
import nc.vo.pfxx.util.PfxxUtils;
import nc.vo.pub.AggregatedValueObject;
import nc.vo.pub.BusinessException;
import nc.vo.pub.CircularlyAccessibleValueObject;
import nc.vo.pub.VOStatus;
import nc.vo.pub.lang.UFBoolean;
import nc.vo.pub.lang.UFDate;
import nc.vo.pub.lang.UFDouble;
import nc.vo.pubapp.pattern.exception.ExceptionUtils;
import nccloud.commons.lang.StringUtils;


public class VoucherPfxxPlugin extends AbstractPfxxPlugin implements IVoucherSave, IVoucherDelete {
    private static final long serialVersionUID = -294638057395954818L;
    protected Object processBill(Object vo, ISwapContext con, AggxsysregisterVO xsysvo) throws BusinessException {
        GLVoucherVO glVO = (GLVoucherVO) vo;
        String docID = con.getDocID();
        String sql = "SELECT busibill \n" +
                "FROM (\n" +
                "  SELECT * \n" +
                "  FROM XX_XLOG \n" +
                "  WHERE DOC_TYPE = 'TTPZD'  \n" +
                "    AND doc_id = 'GDZC_1_累计折旧_0000001618_201811_2018-10-3111' \n" +
                "  ORDER BY ts DESC\n" +
                ") \n" +
                "WHERE ROWNUM = 1 ";
        Object pk_voucher = new BaseDAO().executeQuery(sql, new ColumnProcessor());
        if (pk_voucher == null) {
            glVO.setAttributeValue("pk_voucher", null);
            glVO.setPk_voucher(null);
        }else{
            return pk_voucher;
        }


        GLVoucherAggVO voucherVO = glVO.toVoucherVO();

        VoucherDetailVO[] detailvos = (VoucherDetailVO[]) voucherVO.getChildrenVO();
        UFDouble totalcredit = UFDouble.ZERO_DBL;
        UFDouble totaldebit = UFDouble.ZERO_DBL;
        UFDouble totalgroupcredit = UFDouble.ZERO_DBL;
        UFDouble totalgroupdebit = UFDouble.ZERO_DBL;
        UFDouble totalglobalcredit = UFDouble.ZERO_DBL;
        UFDouble totalglobaldebit = UFDouble.ZERO_DBL;
        voucherVO.getParentVO().getTotalcredit();
        voucherVO.getParentVO().setApprovestatus(-1);
        if (detailvos != null && detailvos.length > 0) {
            for (VoucherDetailVO detailvo : detailvos) {
                if (detailvo.getLocalcreditamount() != null && !UFDouble.ZERO_DBL.equals(detailvo.getLocalcreditamount())) {
                    totalcredit = totalcredit.add((detailvo.getLocalcreditamount() == null) ? UFDouble.ZERO_DBL : detailvo.getLocalcreditamount());
                    totalgroupcredit = totalgroupcredit.add((detailvo.getGroupcreditamount() == null) ? UFDouble.ZERO_DBL : detailvo.getGroupcreditamount());
                    totalglobalcredit = totalglobalcredit.add((detailvo.getGlobalcreditamount() == null) ? UFDouble.ZERO_DBL : detailvo.getGlobalcreditamount());
                } else {
                    totaldebit = totaldebit.add((detailvo.getLocaldebitamount() == null) ? UFDouble.ZERO_DBL : detailvo.getLocaldebitamount());
                    totalgroupdebit = totalgroupdebit.add((detailvo.getGroupdebitamount() == null) ? UFDouble.ZERO_DBL : detailvo.getGroupdebitamount());
                    totalglobaldebit = totalglobaldebit.add((detailvo.getGlobaldebitamount() == null) ? UFDouble.ZERO_DBL : detailvo.getGlobaldebitamount());
                }
            }
            voucherVO.getParentVO().setTotalcredit(totalcredit);
            voucherVO.getParentVO().setTotaldebit(totalcredit);
            voucherVO.getParentVO().setTotalcreditgroup(totalgroupcredit);
            voucherVO.getParentVO().setTotaldebitgroup(totalgroupdebit);
            voucherVO.getParentVO().setTotalcreditglobal(totalglobalcredit);
            voucherVO.getParentVO().setTotaldebitglobal(totalglobaldebit);

        }
        String date = voucherVO.getParentVO().getBilldate().toString();
        setDefaultValue(voucherVO);
        String message = checkVoucherBill(voucherVO, date);
        (new VoucherBillSaveValidate()).validate(voucherVO);
        if (message == null)
            try {
                IplatFormEntry iiplatFormEntry = (IplatFormEntry) NCLocator.getInstance().lookup(IplatFormEntry.class.getName());
                Object obj = iiplatFormEntry.processAction("SAVEBASE", voucherVO.getParentVO().getPk_tradetypecode(), null, (AggregatedValueObject) voucherVO, null, null);
                if (obj != null) {
                    GLVoucherAggVO returnVO = ((GLVoucherAggVO[]) obj)[0];
                    if (GLStartCheckUtil.checkProductStart("1056"))
                        VoucherBillUtil.syncRPBill(returnVO, (voucherVO.getPrimaryKey() == null) ? RPBillConvertUtil.OPER_INSERT : RPBillConvertUtil.OPER_UPDATE);
//		          if ("Y".equals(isapprove)) {
//		            Object approveObj = sendApproveVoucherBill(returnVO, voucherWebVO);
//		            if (!(approveObj instanceof AggregatedValueObject)) {
//		              ReturnObjException err = new ReturnObjException();
//		              err.setReturnObj(approveObj);
//		              throw err;
//		            }
//		            returnVO = (GLVoucherAggVO)approveObj;
//		          }
                    return returnVO.getParentVO().getPk_voucher();
                }
            } catch (Exception e) {
                if (e instanceof ReturnObjException)
                    throw e;
                ExceptionUtils.wrappException(e);
            }
        return null;

    }

    private int getVoucherNum(ISwapContext con) {
        int voucherNum = 0;
        if (con != null)
            try {
                String billtype = con.getBilltype();
                String docID = con.getDocID();
                int indexOf = docID.indexOf(billtype);
                String subStr = docID.substring(indexOf + billtype.length(), docID
                        .length());
                voucherNum = Integer.valueOf(subStr).intValue() + 1;
            } catch (Exception e) {
                Logger.error(e);
            }
        return voucherNum;
    }

    private Object processSaveVoucher(VoucherVO vo, ISwapContext con, AggxsysregisterVO xsysvo, int voucherNum) throws GLBusinessException {
        Object result = doSaveVoucher(vo, con, xsysvo, voucherNum);
        return result;
    }

    private Object doSaveVoucher(VoucherVO vo, ISwapContext con, AggxsysregisterVO xsysvo, int voucherNum) throws GLBusinessException {
        VoucherVO vouchervo = null;
        changePeriod(vo);
        try {
            checkValdata(vo);
            if (vo.getPk_group() == null)
                vo.setPk_group(con.getPk_group());
            if (PKLock.getInstance().addDynamicLock(con.getDocID() + con.getBilltype())) {
                isExists(vo, con);
            } else {
                throw new GLBusinessException(
                        NCLangRes4VoTransl.getNCLangRes().getStrByID("20021005", "UPT2002100573-900071"));
            }
            GLPluginUtils.defaultDataSet(vo, false, voucherNum);
            vouchervo = GLPluginUtils.setVoucherDefault(vo, xsysvo, con);
            formatNumberDetail(vouchervo);
        } catch (Exception e) {
            Logger.error("凭证保存前数据效验报错:" + e.getMessage(), e);
            throw new GLBusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("private20111017_0", "02002001-0212") + e.getMessage(), e);
        }
        OperationResultVO[] saveResult = null;
        try {
            String pk_mamager = vouchervo.getPk_manager();
            vouchervo.setPk_manager(null);
            IVoucher voucherbo = (IVoucher) NCLocator.getInstance().lookup(IVoucher.class.getName());
            if (vouchervo.getDiscardflag().booleanValue()) {
                vouchervo.setDiscardflag(UFBoolean.FALSE);
                saveResult = voucherbo.save(vouchervo, Boolean.TRUE);
                IVoucherList voucherlistbo = (IVoucherList) NCLocator.getInstance().lookup(IVoucherList.class.getName());
                voucherlistbo.abandonVoucherByPk(vouchervo.getPk_voucher(), vouchervo.getPk_prepared(), Boolean.TRUE);
            } else {
                saveResult = voucherbo.save(vouchervo, Boolean.TRUE);
            }
            if (!StringUtils.isEmpty(pk_mamager)) {
                TallyConditionVO conditionVO = new TallyConditionVO();
                conditionVO.setPk_accountingbook(vouchervo.getPk_accountingbook());
                conditionVO.setYear(vouchervo.getYear());
                conditionVO.setPeriods(new String[]{vouchervo.getPeriod()});
                conditionVO.setStrVoucherPK(new String[]{vouchervo.getPk_voucher()});
                conditionVO.setStrManager(pk_mamager);
                conditionVO.setTallyDate((vouchervo.getTallydate() == null) ? new UFDate() : vouchervo.getTallydate());
                conditionVO.setOp(UFBoolean.TRUE);
                ((IVoucherTally) NCLocator.getInstance().lookup(IVoucherTally.class)).tallyVoucherByPks(conditionVO);
            }
            if (vouchervo.getStatus() == 3) {
                Logger.debug("执行凭证删除方法!");
            } else {
                Logger.debug("proc = " + vouchervo.getStatus());
            }
        } catch (Exception e) {
            Logger.error("凭证保存中报错:" + e.getMessage(), e);
            throw new GLBusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("private20111017_0", "02002001-0213") + e.getMessage(), e);
        }
        return saveResult;
    }

    private void changePeriod(VoucherVO vo) throws GlBusinessException {
        String defaultpk_accperiodscheme = AccountBookUtil.getAccPeriodSchemePKByAccountingbookPk(vo.getPk_accountingbook());
        AccountCalendar caldar = AccountCalendar.getInstanceByPeriodScheme(defaultpk_accperiodscheme);
        try {
            caldar.setDate(vo.getPrepareddate());
            String yearmth = caldar.getMonthVO().getYearmth();
            String[] year_mth = yearmth.split("-");
            vo.setYear(year_mth[0]);
            vo.setPeriod(year_mth[1]);
        } catch (Exception e) {
            Logger.error(e.getMessage(), e);
            throw new GlBusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("private20111017_0", "02002001-0216"), e);
        }
    }

    private void isExists(VoucherVO vo, ISwapContext con) throws DAOException, BusinessException {
        if (con.getDocID() != null) {
            List<IDContrastVO> idc = (List<IDContrastVO>) (new BaseDAO()).retrieveByClause(IDContrastVO.class, "file_id='" + con.getDocID() + "' and bill_type='" + con.getBilltype() + "'");
            if (!idc.isEmpty() && idc.size() > 0) {
                String pk_vouhcer = ((IDContrastVO) idc.get(0)).getPk_bill();
                vo.setPk_voucher(pk_vouhcer);
                if ("N".equals(con.getReplace()))
                    throw new BusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("private20111017_0", "02002001-0214"));
            }
        }
    }

    private void checkValdata(VoucherVO vo) throws BusinessException {
        if (vo.getPk_prepared() == null)
            throw new BusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("private20111017_0", "02002001-0215"));
        if (vo.getPk_prepared().equals(vo.getPk_checked()))
            throw new BusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("private20111017_0", "02002001-0202"));
        String localCurrency = Currency.getLocalCurrPK(vo.getPk_accountingbook());
        for (int i = 0; i < vo.getDetail().size(); i++) {
            DetailVO detailVo = (DetailVO) vo.getDetail().get(i);
            String pk_currtype = detailVo.getPk_currtype();
            if (pk_currtype.equals(localCurrency)) {
                UFDouble value = detailVo.getLocalcreditamount();
                if (detailVo.getLocalcreditamount() == null || detailVo.getLocalcreditamount().equals(UFDouble.ZERO_DBL))
                    value = detailVo.getLocaldebitamount();
                UFDouble value2 = detailVo.getCreditamount();
                if (detailVo.getCreditamount() == null || detailVo.getCreditamount().equals(UFDouble.ZERO_DBL))
                    value2 = detailVo.getDebitamount();
                boolean isEqual = isEquale(value2, value);
                if (!isEqual)
                    throw new BusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("glpub_0", "02002003-0286", null, new String[]{String.valueOf(i + 1)}));
            }
        }
    }

    private boolean isEquale(UFDouble value1, UFDouble value2) {
        if (value1 == null)
            value1 = UFDouble.ZERO_DBL;
        if (value2 == null)
            value2 = UFDouble.ZERO_DBL;
        return value1.equals(value2);
    }

    public OperationResultVO[] afterDelete(VoucherOperateInterfaceVO vo) throws BusinessException {
        return null;
    }

    public OperationResultVO[] afterSave(VoucherSaveInterfaceVO vo) throws BusinessException {
        IDContrastVO ufvo = null;
        try {
            Logger.debug(">>>>>>>>>>>>>>>>>>>>>>>>>>>>> 进入afterSave方法...");
            if (vo.voucher.getUserData() != null && vo.voucher.getUserData() instanceof IDContrastVO) {
                Logger.debug(">>>>>>>>>>>>>>>>>>>>>> afterSave 从外部交换平台进入add & edit...");
                ufvo = (IDContrastVO) vo.voucher.getUserData();
                Integer voucherkind = vo.voucher.getVoucherkind();
                if (voucherkind != null && voucherkind.intValue() == 2) {
                    Logger.debug(">>>>>>>>>>>>>>>>>>>>>>> 期初凭证不增加线索号和凭证主键的对应关系...");
                } else {
                    ufvo.setPk_bill(vo.voucher.getPk_voucher());
                    ufvo.setStatus(2);
                    PfxxUtils.lookUpPFxxEJBService().insertIDvsPK(ufvo);
                }
            }
        } catch (Exception e) {
            Logger.error(e.getMessage(), e);
            throw new BusinessException(e + NCLangResOnserver.getInstance().getStrByID("pfxx", "UPPpfxx-000211"));
        }
        return null;
    }

    public OperationResultVO[] beforeSave(VoucherSaveInterfaceVO vo) throws BusinessException {
        return null;
    }

    public OperationResultVO[] beforeDelete(VoucherOperateInterfaceVO vo) throws BusinessException {
        List<OperationResultVO> resultList = new ArrayList<>();
        try {
            if (vo.pk_vouchers != null) {
                Logger.debug(">>>>>>>>>>>>>>>>>>> 从总帐进入要删除外部交换平台导入的凭证...");
                IGlPara glparabo = (IGlPara) NCLocator.getInstance().lookup(IGlPara.class.getName());
                for (int i = 0; i < ((vo.pk_vouchers == null) ? 0 : vo.pk_vouchers.length); i++) {
                    VoucherVO vouchervo = GLPluginUtils.findVoucherVOByVoucherPK(vo.pk_vouchers[i].toString());
                    List<IDContrastVO> con = (List<IDContrastVO>) (new BaseDAO()).retrieveByClause(IDContrastVO.class, "pk_bill='" + vo.pk_vouchers[i] + "'");
                    UFBoolean parval = glparabo.isDelInputVoucherOut(vouchervo.getPk_accountingbook());
                    if (parval == null)
                        throw new BusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("20021010", "UPP20021005-000711"));
                    boolean isPowerDelVoucher = parval.booleanValue();
                    if (!con.isEmpty()) {
                        for (int j = 0; j < con.size(); j++) {
                            if (!((IDContrastVO) con.get(j)).getIsdelete().booleanValue()) {
                                OperationResultVO rs = new OperationResultVO();
                                rs.m_intSuccess = 2;
                                rs.m_strDescription = NCLangRes4VoTransl.getNCLangRes().getStrByID("private20111017_0", "02002001-0203");
                                resultList.add(rs);
                            } else if (isPowerDelVoucher) {
                                PfxxUtils.lookUpPFxxEJBService().deleteIDvsPKByDocPK(vo.pk_vouchers[i]);
                            }
                        }
                        if (!isPowerDelVoucher) {
                            Logger.debug("不允许强制删除外系统导入的凭证");
                            OperationResultVO rs = new OperationResultVO();
                            rs.m_intSuccess = 2;
                            rs.m_strDescription = NCLangRes4VoTransl.getNCLangRes().getStrByID("private20111017_0", "02002001-0226");
                            resultList.add(rs);
                        }
                    }
                }
            }
        } catch (Exception e) {
            Logger.error(e.getMessage(), e);
            throw new BusinessException(e + "");
        }
        return resultList.<OperationResultVO>toArray(new OperationResultVO[0]);
    }

    public void formatNumberDetail(VoucherVO voucher) throws BusinessException {
        Vector<DetailVO> detailList = voucher.getDetail();
        UFDouble value = null;
        Integer digit = Integer.valueOf(0);
        for (DetailVO detailVO : detailList) {
            value = detailVO.getDebitamount();
            if (value != null) {
                if (!value.equals(UFDouble.ZERO_DBL)) {
                    digit = Currency.getCurrDigit(detailVO.getPk_currtype());
                    if (digit == null)
                        digit = Integer.valueOf(2);
                    value = value.setScale(Math.abs(digit.intValue()), 4);
                    detailVO.setDebitamount(value);
                }
            } else {
                value = UFDouble.ZERO_DBL;
                detailVO.setDebitamount(value);
            }
            value = detailVO.getCreditamount();
            if (value != null) {
                if (!value.equals(UFDouble.ZERO_DBL)) {
                    digit = Currency.getCurrDigit(detailVO.getPk_currtype());
                    if (digit == null)
                        digit = Integer.valueOf(2);
                    value = value.setScale(Math.abs(digit.intValue()), 4);
                    detailVO.setCreditamount(value);
                }
            } else {
                value = UFDouble.ZERO_DBL;
                detailVO.setCreditamount(value);
            }
            value = detailVO.getLocaldebitamount();
            if (value != null) {
                if (!value.equals(UFDouble.ZERO_DBL)) {
                    digit = Currency.getCurrDigit(Currency.getLocalCurrPK(voucher.getPk_accountingbook()));
                    if (digit == null)
                        digit = Integer.valueOf(2);
                    value = value.setScale(Math.abs(digit.intValue()), 4);
                    detailVO.setLocaldebitamount(value);
                }
            } else {
                value = UFDouble.ZERO_DBL;
                detailVO.setLocaldebitamount(value);
            }
            value = detailVO.getLocalcreditamount();
            if (value != null) {
                if (!value.equals(UFDouble.ZERO_DBL)) {
                    digit = Currency.getCurrDigit(Currency.getLocalCurrPK(voucher.getPk_accountingbook()));
                    if (digit == null)
                        digit = Integer.valueOf(2);
                    value = value.setScale(Math.abs(digit.intValue()), 4);
                    detailVO.setLocalcreditamount(value);
                }
            } else {
                value = UFDouble.ZERO_DBL;
                detailVO.setLocalcreditamount(value);
            }
            value = detailVO.getGroupdebitamount();
            if (value != null) {
                if (!value.equals(UFDouble.ZERO_DBL)) {
                    digit = Currency.getCurrDigit(Currency.getGroupCurrpk(voucher.getPk_group()));
                    if (digit == null)
                        digit = Integer.valueOf(2);
                    value = value.setScale(Math.abs(digit.intValue()), 4);
                    detailVO.setGroupdebitamount(value);
                }
            } else {
                value = UFDouble.ZERO_DBL;
                detailVO.setGroupdebitamount(value);
            }
            value = detailVO.getGroupcreditamount();
            if (value != null) {
                if (!value.equals(UFDouble.ZERO_DBL)) {
                    digit = Currency.getCurrDigit(Currency.getGroupCurrpk(voucher.getPk_group()));
                    if (digit == null)
                        digit = Integer.valueOf(2);
                    value = value.setScale(Math.abs(digit.intValue()), 4);
                    detailVO.setGroupcreditamount(value);
                }
            } else {
                value = UFDouble.ZERO_DBL;
                detailVO.setGroupcreditamount(value);
            }
            value = detailVO.getGlobaldebitamount();
            if (value != null) {
                if (!value.equals(UFDouble.ZERO_DBL)) {
                    digit = Currency.getCurrDigit(Currency.getGlobalCurrPk(null));
                    if (digit == null)
                        digit = Integer.valueOf(2);
                    value = value.setScale(Math.abs(digit.intValue()), 4);
                    detailVO.setGlobaldebitamount(value);
                }
            } else {
                value = UFDouble.ZERO_DBL;
                detailVO.setGlobaldebitamount(value);
                digit = Currency.getCurrDigit(Currency.getGlobalCurrPk(null));
            }
            value = detailVO.getGlobalcreditamount();
            if (value != null) {
                if (!value.equals(UFDouble.ZERO_DBL)) {
                    digit = Currency.getCurrDigit(Currency.getGlobalCurrPk(null));
                    if (digit == null)
                        digit = Integer.valueOf(2);
                    value = value.setScale(Math.abs(digit.intValue()), 4);
                    detailVO.setGlobalcreditamount(value);
                }
                continue;
            }
            value = UFDouble.ZERO_DBL;
            detailVO.setGlobalcreditamount(value);
        }
    }


    public void setDefaultValue(GLVoucherAggVO voucherAggVO) throws BusinessException {
        GLVoucherVO voucherVO = voucherAggVO.getParentVO();
        String billtypecode = voucherVO.getPk_tradetypecode();
        String pk_billtypeid = voucherVO.getPk_tradetypeid();
        if (pk_billtypeid != null && pk_billtypeid.length() > 0) {
            billtypecode = PfUtilBaseTools.getBillTypeCodeByPK(pk_billtypeid);
            if (billtypecode != null)
                voucherVO.setPk_tradetypecode(billtypecode);
        }
        if (StringUtil.isEmptyWithTrim(voucherVO.getPk_org_v())) {
            HashMap<String, String> vidMap = ((IBasicOrgUnitPubService_C) NCLocator.getInstance().lookup(IBasicOrgUnitPubService_C.class)).getNewVIDSByOrgIDSAndDate(new String[]{voucherVO
                    .getPk_org()}, voucherVO
                    .getBilldate().asEnd());
            if (vidMap.containsKey(voucherVO.getPk_org()))
                voucherVO.setPk_org_v(vidMap.get(voucherVO.getPk_org()));
        }
        AccountCalendar calendar = CalendarUtilGL.getAccountCalendarByAccountBook(voucherVO.getPk_accountingbook());
        calendar.setDate(voucherVO.getBilldate());
        voucherVO.setYear(calendar.getYearVO().getPeriodyear());
        voucherVO.setPeriod(calendar.getMonthVO().getAccperiodmth());
        VoucherDetailVO[] details = (VoucherDetailVO[]) voucherAggVO.getChildrenVO();
        if (details != null) {
            Set<String> unitSet = new HashSet<>();
            for (VoucherDetailVO detailVO : details) {
                detailVO.setPk_org(voucherVO.getPk_org());
                detailVO.setPk_org_v(voucherVO.getPk_org_v());
                if (!StringUtil.isEmptyWithTrim(detailVO.getPk_unit())) {
                    unitSet.add(detailVO.getPk_unit());
                } else {
                    detailVO.setPk_unit(voucherVO.getPk_org());
                    detailVO.setPk_unit_v(voucherVO.getPk_org_v());
                }
            }
            if (unitSet.size() > 0) {
                HashMap<String, String> vidMap = ((IBasicOrgUnitPubService_C) NCLocator.getInstance().lookup(IBasicOrgUnitPubService_C.class)).getNewVIDSByOrgIDSAndDate(unitSet
                        .<String>toArray(new String[0]), voucherVO
                        .getBilldate().asEnd());
                if (vidMap != null)
                    for (VoucherDetailVO detailVO : details) {
                        if (!StringUtil.isEmptyWithTrim(detailVO.getPk_unit()))
                            detailVO.setPk_unit_v(vidMap.get(detailVO.getPk_unit()));
                    }
            }
        }
    }


    public String checkVoucherBill(GLVoucherAggVO voucherVO, String date) throws BusinessException {
        String pk_org = voucherVO.getParentVO().getPk_org();
        VoucherDetailVO[] details = (VoucherDetailVO[]) voucherVO.getChildrenVO();
        String message = null;
        if (pk_org == null)
            throw new BusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("voucherbill", "voucherbill-000012"));
        String[] pk_accsubj = new String[details.length];
        voucherVO.getParentVO().getTotaldebit();
        voucherVO.getParentVO().getTotalcredit();
        if (details != null) {
            Set<String> assidSet = new HashSet<>();
            Set<String> pk_unitSet = new HashSet<>();
            for (int i = 0; i < details.length; i++) {
                if (details[i].getPk_accasoa() == null)
                    throw new BusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("voucherbill", "voucherbill-000013"));
                if ((details[i].getLocalcreditamount() == null || details[i].getLocalcreditamount().doubleValue() == 0.0D) && (details[i]
                        .getLocaldebitamount() == null || details[i].getLocaldebitamount().doubleValue() == 0.0D))
                    throw new BusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("voucherbill", "voucherbill-000014") +
                            NCLangResOnserver.getInstance().getStrByID("20021005", "UPP20021005-000575", null, new String[]{String.valueOf(i + 1)}));
                pk_accsubj[i] = details[i].getPk_accasoa();
                if (!StringUtil.isEmptyWithTrim(details[i].getAssid()))
                    assidSet.add(details[i].getAssid());
                if (!StringUtil.isEmptyWithTrim(details[i].getPk_unit()))
                    pk_unitSet.add(details[i].getPk_unit());
            }
            double cre = (voucherVO.getParentVO().getTotalcredit() == null) ? 0.0D : voucherVO.getParentVO().getTotalcredit().toDouble().doubleValue();
            double deb = (voucherVO.getParentVO().getTotaldebit() == null) ? 0.0D : voucherVO.getParentVO().getTotaldebit().toDouble().doubleValue();
            if (cre != deb)
                throw new BusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("voucherbill", "voucherbill-000015"));
            AccountVO[] acc = AccountUtilGL.queryByPks(pk_accsubj, date);
            HashMap<Object, Object> tempaccsubj = new HashMap<>();
            if (tempaccsubj.size() == 0) {
                AccountVO voTemp = null;
                if (acc != null)
                    for (int j = 0; j < acc.length; j++) {
                        voTemp = acc[j];
                        tempaccsubj.put(voTemp.getPk_accasoa(), voTemp);
                    }
            }
            ConcurrentHashMap<String, AssVO[]> assMap = ((IFreevaluePub) NCLocator.getInstance().lookup(IFreevaluePub.class)).queryAssvosByAssids(assidSet.<String>toArray(new String[0]), Module.GL);
            if (assMap == null) {
                assMap = (ConcurrentHashMap) new ConcurrentHashMap<>();
            }
            IOrgRelationDataPubService service = (IOrgRelationDataPubService) NCLocator.getInstance().lookup(IOrgRelationDataPubService.class);
            Map<String, List<String>> relationMap = service.queryOrgUnitByPkFinanceorg(pk_unitSet.<String>toArray(new String[0]));
            IBusiFuncQryPubService busiService = (IBusiFuncQryPubService) NCLocator.getInstance().lookup(IBusiFuncQryPubService.class);
            Map<String, String[]> mapPkorgAndFuncs = (Map) new HashMap<>();
            for (String pk_unit : pk_unitSet) {
                mapPkorgAndFuncs.put(pk_unit, new String[]{"all"});
            }
            if (relationMap != null) {
                String[] relations = (String[]) relationMap.keySet().toArray((Object[]) new String[0]);
                for (String relation : relations) {
                    for (String unit : relationMap.get(relation)) {
                        mapPkorgAndFuncs.put(unit, new String[]{"all"});
                    }
                }
                Map<String, List<String>> roleMap = busiService.queryAdminOrgsByBusiFunc(mapPkorgAndFuncs);
                if (roleMap != null)
                    relationMap.putAll(roleMap);
            } else {
                relationMap = busiService.queryAdminOrgsByBusiFunc(mapPkorgAndFuncs);
            }
            GLParameterVO glparam = new GLParameterVO();
            glparam.Parameter_isfreevalueallownull = UFBoolean.TRUE;
            OperationResultVO[] result = null;
            try {
                catAss(details);
                RuleQueryVO[] rulequeryvos = new RuleQueryVO[details.length];
                String pk_accountingbook = voucherVO.getParentVO().getPk_accountingbook();
                String pk_setofbook = AccountBookUtil.getAccountingBookVOByPrimaryKey(voucherVO.getParentVO().getPk_accountingbook()).getPk_setofbook();
                for (int j = 0; j < details.length; j++) {
                    if (!acc[j].getEndflag().booleanValue())
                        throw new BusinessException("会计科目非末级");
                    result = checkAssValidate(details[j], j, voucherVO.getParentVO().getBilldate().toStdString(), result, (Map<String, AssVO[]>) assMap, relationMap);
                    result = checkAss(details[j], j, glparam, result, (AccountVO) tempaccsubj.get(details[j].getPk_accasoa()), (Map<String, AssVO[]>) assMap, voucherVO.getParentVO().getPk_group());
                    result = checkAssNotNull(details[j], j, result, (AccountVO) tempaccsubj.get(details[j].getPk_accasoa()));
                    rulequeryvos[j] = new RuleQueryVO();
                    rulequeryvos[j].setPk_corp(details[j].getPk_org());
                    rulequeryvos[j].setPk_glorgbook(pk_accountingbook);
                    rulequeryvos[j].setSubject(details[j].getPk_accasoa());
                    rulequeryvos[j].setVO(details[j].getAss());
                    rulequeryvos[j].setStddate(voucherVO.getParentVO().getBilldate().toStdString());
                    rulequeryvos[j].setRowIndex(j + 1);
                    rulequeryvos[j].setPk_unit(details[j].getPk_unit());
                    rulequeryvos[j].setPk_setofbook(pk_setofbook);
                    rulequeryvos[j].setPk_group(voucherVO.getParentVO().getPk_group());
                }
                nc.vo.fipub.rulecheck.OperationResultVO[][] rs1 = GLPubProxy.getRemoteIRuleCheckPrv().checkValuesGroupBySubject(rulequeryvos, tempaccsubj);
                if (rs1 != null)
                    for (int k = 0; k < rs1.length; k++) {
                        if (rs1[k] != null)
                            for (nc.vo.fipub.rulecheck.OperationResultVO checkrs : rs1[k]) {
                                if (checkrs != null) {
                                    OperationResultVO operationResultVO = new OperationResultVO();
                                    operationResultVO = new OperationResultVO();
                                    operationResultVO.m_intSuccess = checkrs.m_intSuccess;
                                    operationResultVO.m_strPK = checkrs.m_strPK;
                                    operationResultVO.m_strDescription = checkrs.m_strDescription;
                                    operationResultVO.m_userIdentical = checkrs.m_userIdentical;
                                    result = OperationResultVO.appendResultVO(result, new OperationResultVO[]{operationResultVO});
                                }
                            }
                    }
                OperationResultVO[] rs = (new VoucherCheckBO()).checkSubjRuleForVoucherBill(voucherVO, tempaccsubj);
                result = OperationResultVO.appendResultVO(result, rs);
                if (result != null) {
                    StringBuffer strMsg = new StringBuffer();
                    boolean errflag = false;
                    for (int k = 0; k < result.length; k++) {
                        switch ((result[k]).m_intSuccess) {
                            case 0:
                                break;
                            case 1:
                                strMsg.append(NCLangResOnserver.getInstance().getStrByID("2002100556", "UPP2002100556-000119") + (result[k]).m_strDescription + "\n");
                                break;
                            case 2:
                                errflag = true;
                                strMsg.append(NCLangResOnserver.getInstance().getStrByID("2002100556", "UPP2002100556-000120") + (result[k]).m_strDescription + "\n");
                                break;
                            default:
                                strMsg.append(NCLangResOnserver.getInstance().getStrByID("2002100556", "UPP2002100556-000121") + (result[k]).m_strDescription + "\n");
                                break;
                        }
                    }
                    if (strMsg.length() > 0 && errflag)
                        throw new BusinessException(strMsg.toString());
                }
            } catch (Exception ex) {
                ExceptionUtils.wrappBusinessException(ex.getMessage());
            }
        } else {
            throw new BusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("voucherbill", "voucherbill-000016"));
        }
        (new VoucherBillSaveValidate()).validate(voucherVO);
        return message;
    }


    private VoucherDetailVO[] catAss(VoucherDetailVO[] details) throws BusinessException {
        if (details == null || details.length == 0)
            return details;
        String[] Ids = null;
        Vector<String> vecIds = new Vector();
        HashMap<Object, Object> tempmap = new HashMap<>();
        for (int j = 0; j < details.length; j++) {
            if (details[j].getAssid() != null && !"".equals(details[j].getAssid()))
                if (details[j].getAss() == null && tempmap.get(details[j].getAssid()) == null) {
                    vecIds.addElement(details[j].getAssid());
                    tempmap.put(details[j].getAssid(), details[j].getAssid());
                }
        }
        if (vecIds.size() == 0)
            return details;
        Ids = new String[vecIds.size()];
        vecIds.copyInto((Object[]) Ids);
        IFreevaluePub dmo = (IFreevaluePub) NCLocator.getInstance().lookup(IFreevaluePub.class);
        GlAssVO[] glAssVo = dmo.queryAllByIDs(Ids, null, Module.GL);
        if (glAssVo == null)
            throw new BusinessException("Error AssIDs::" + vecIds);
        HashMap<Object, Object> assvocache = new HashMap<>();
        int i;
        for (i = 0; i < glAssVo.length; i++) {
            glAssVo[i].setAssID(glAssVo[i].getAssID().trim());
            assvocache.put(glAssVo[i].getAssID(), glAssVo[i].getAssVos());
        }
        for (i = 0; i < details.length; i++) {
            if (details[i].getAssid() != null && details[i].getAss() == null)
                details[i].setAss((AssVO[]) assvocache.get(details[i].getAssid()));
        }
        return details;
    }

    private OperationResultVO[] checkAssValidate(VoucherDetailVO detail, int i, String prepareddate, OperationResultVO[] result, Map<String, AssVO[]> assMap, Map<String, List<String>> relationMap) {
        String assid = detail.getAssid();
        AssVO[] assVOs = detail.getAss();
        try {
            if (StringUtils.isNotEmpty(assid) && assVOs != null && assVOs.length > 0)
                for (AssVO assVo : assVOs) {
                    String pk_checkvalue = assVo.getPk_Checkvalue();
                    if (StringUtils.isNotEmpty(pk_checkvalue) && !"~".equals(pk_checkvalue)) {
                        OperationResultVO rs = new OperationResultVO();
                        IGeneralAccessor accessor = GeneralAccessorFactory.getAccessor(assVo.getM_classid());
                        if (accessor == null || accessor instanceof nc.vo.bd.accessor.NullGeneralAccessor)
                            continue;
                        IBDData bdData = accessor.getDocByPk(pk_checkvalue);
                        if (bdData == null) {
                            rs.m_intSuccess = 2;
                            rs

                                    .m_strDescription = NCLangResOnserver.getInstance().getStrByID("20021005", "UPT2002100573-900057", null, new String[]{assVo.getChecktypename()}) + NCLangResOnserver.getInstance().getStrByID("20021005", "UPP20021005-000575", null, new String[]{String.valueOf(i + 1)});
                            result = OperationResultVO.appendResultVO(result, new OperationResultVO[]{rs});
                            continue;
                        }
                        String code = bdData.getCode();
                        if (bdData instanceof BankaccsubBDDataVO)
                            code = ((BankaccsubBDDataVO) bdData).getSubcode();
                        if (assVo.getM_classid().equals("40d39c26-a2b6-4f16-a018-45664cac1a1f") || assVo
                                .getM_classid().equals("b26fa3cb-4087-4027-a3b6-c83ab2a086a9")) {
                            if (detail.getPk_unit().equals(bdData.getPk_org()))
                                continue;
                            if (relationMap == null)
                                relationMap = new HashMap<>();
                            if (relationMap != null && relationMap.size() > 0 && relationMap
                                    .get(detail.getPk_unit()) != null) {
                                List<String> relationList = relationMap.get(detail.getPk_unit());
                                if (relationList.contains(bdData.getPk_org()))
                                    continue;
                            }
                            boolean subContain = false;
                            if (relationMap.get(detail.getPk_unit()) != null)
                                for (String relation : relationMap.get(detail.getPk_unit())) {
                                    if (relationMap.get(relation + "#all") != null) {
                                        List<String> relationList = relationMap.get(relation + "#all");
                                        if (relationList.contains(bdData.getPk_org())) {
                                            subContain = true;
                                            break;
                                        }
                                    }
                                }
                            if (!subContain) {
                                if (relationMap != null && relationMap.size() > 0 && relationMap
                                        .get(detail.getPk_unit() + "#all") != null) {
                                    List<String> relationList = relationMap.get(detail.getPk_unit() + "#all");
                                    if (relationList.contains(bdData.getPk_org()))
                                        continue;
                                }
                                if (assVo.getM_classid().equals("40d39c26-a2b6-4f16-a018-45664cac1a1f")) {
                                    StringBuffer sqlOrgs = new StringBuffer();
                                    SQLParameter parameterOrgs = new SQLParameter();
                                    sqlOrgs.append("select pk_org from bd_psnjob where pk_psndoc = ? ");
                                    parameterOrgs.addParam(bdData.getPk());
                                    sqlOrgs.append(" and bd_psnjob.indutydate <= ? ");
                                    parameterOrgs.addParam(prepareddate.substring(0, 10));
                                    ArrayList org_List = (ArrayList) (new BaseDAO()).executeQuery(sqlOrgs.toString(), parameterOrgs, (ResultSetProcessor) new ColumnListProcessor());
                                    Boolean find = Boolean.valueOf(false);
                                    for (int j = 0; j < org_List.size(); j++) {
                                        if (detail.getPk_unit().equals(org_List.get(j))) {
                                            find = Boolean.valueOf(true);
                                            break;
                                        }
                                    }
                                    if (relationMap != null && relationMap.size() > 0 && relationMap
                                            .get(detail.getPk_unit()) != null) {
                                        List<String> relationList = relationMap.get(detail.getPk_unit());
                                        for (int k = 0; k < org_List.size(); k++) {
                                            if (relationList.contains(org_List.get(k))) {
                                                find = Boolean.valueOf(true);
                                                break;
                                            }
                                        }
                                    }
                                    if (find.booleanValue())
                                        continue;
                                }
                                rs.m_intSuccess = 2;
                                rs

                                        .m_strDescription = NCLangResOnserver.getInstance().getStrByID("20021005", "UPT2002100573-900057", null, new String[]{assVo.getChecktypename()}) + NCLangResOnserver.getInstance().getStrByID("20021005", "UPP20021005-000575", null, new String[]{String.valueOf(i + 1)});
                                result = OperationResultVO.appendResultVO(result, new OperationResultVO[]{rs});
                            }
                            continue;
                        }
                        IBDData docByCode = accessor.getDocByCode(detail.getPk_org(), code);
                        if (docByCode == null || !pk_checkvalue.equals(docByCode.getPk())) {
                            rs.m_intSuccess = 2;
                            rs

                                    .m_strDescription = NCLangResOnserver.getInstance().getStrByID("20021005", "UPT2002100573-900057", null, new String[]{assVo.getChecktypename()}) + NCLangResOnserver.getInstance().getStrByID("20021005", "UPP20021005-000575", null, new String[]{String.valueOf(i + 1)});
                            result = OperationResultVO.appendResultVO(result, new OperationResultVO[]{rs});
                        }
                    }
                    continue;
                }
        } catch (Exception e) {
            Logger.error(e);
        }
        return result;
    }

    private OperationResultVO[] checkAss(VoucherDetailVO detail, int i, GLParameterVO glparam, OperationResultVO[] result, AccountVO accvo, Map<String, AssVO[]> assMap, String pk_group) throws GLBusinessException, Exception, NamingException, SystemException {
        boolean isCheckEmpty = true;
        AccAssVO[] accass = accvo.getAccass();
        AssVO[] detailass = detail.getAss();
        if (accass != null && accass.length > 0)
            if (detail.getAssid() == null) {
                if (detailass == null || detailass.length == 0) {
                    for (AccAssVO accAssVO : accass) {
                        if (accAssVO.getIsempty() != null && !accAssVO.getIsempty().booleanValue() && isCheckEmpty) {
                            OperationResultVO rs = new OperationResultVO();
                            rs.m_intSuccess = 2;
                            rs

                                    .m_strDescription = (new VoucherCheckMessage()).getVoucherMessage(10022) + NCLangResOnserver.getInstance().getStrByID("20021005", "UPP20021005-000575", null, new String[]{String.valueOf(i + 1)});
                            rs
                                    .m_strDescription = rs.m_strDescription + AccAssItemCache.getAccAssitemNameByPK(accAssVO.getPk_entity());
                            result = OperationResultVO.appendResultVO(result, new OperationResultVO[]{rs});
                        } else {
                            detailass = new AssVO[accass.length];
                            for (int m = 0; m < detailass.length; m++) {
                                detailass[m] = new AssVO();
                                detailass[m].setPk_Checktype(accass[m].getPk_entity());
                            }
                            IFreevaluePub freevalue = (IFreevaluePub) NCLocator.getInstance().lookup(IFreevaluePub.class);
                            detail.setAssid(freevalue
                                    .getAssID(detailass, Boolean.TRUE, pk_group, Module.GL));
                            detail.setAss(detailass);
                        }
                    }
                } else {
                    IFreevaluePub freevalue = (IFreevaluePub) NCLocator.getInstance().lookup(IFreevaluePub.class);
                    detail.setAssid(freevalue
                            .getAssID(detailass, Boolean.TRUE, pk_group, Module.GL));
                    detail.setAss(detailass);
                }
            } else {
                if (detailass == null) {
                    if (assMap.get(detail.getAssid()) != null) {
                        detailass = assMap.get(detail.getAssid());
                    } else {
                        detailass = ((IFreevaluePub) NCLocator.getInstance().lookup(IFreevaluePub.class)).queryAssvosByid(detail.getAssid(), Module.GL);
                    }
                    detail.setAss(detailass);
                }
                if (detailass == null || detailass.length == 0) {
                    if (!glparam.Parameter_isfreevalueallownull.booleanValue() && isCheckEmpty) {
                        OperationResultVO rs = new OperationResultVO();
                        rs.m_intSuccess = 2;
                        rs

                                .m_strDescription = (new VoucherCheckMessage()).getVoucherMessage(10022) + NCLangResOnserver.getInstance().getStrByID("20021005", "UPP20021005-000575", null, new String[]{String.valueOf(i + 1)});
                        result = OperationResultVO.appendResultVO(result, new OperationResultVO[]{rs});
                    } else {
                        detailass = new AssVO[accass.length];
                        for (int m = 0; m < detailass.length; m++) {
                            detailass[m] = new AssVO();
                            detailass[m].setPk_Checktype(accass[m].getPk_entity());
                        }
                        IFreevaluePub freevalue = (IFreevaluePub) NCLocator.getInstance().lookup(IFreevaluePub.class);
                        detail.setAssid(freevalue
                                .getAssID(detailass, Boolean.TRUE, pk_group, Module.GL));
                        detail.setAss(detailass);
                    }
                } else if (detailass.length != accass.length) {
                    OperationResultVO rs = new OperationResultVO();
                    rs.m_intSuccess = 2;
                    rs

                            .m_strDescription = (new VoucherCheckMessage()).getVoucherMessage(10023) + NCLangResOnserver.getInstance().getStrByID("20021005", "UPP20021005-000580", null, new String[]{String.valueOf(i + 1)}) + detail.getAssid();
                    result = OperationResultVO.appendResultVO(result, new OperationResultVO[]{rs});
                } else {
                    HashMap<Object, Object> tmpassmap = new HashMap<>();
                    for (int j = 0; j < detailass.length; j++) {
                        if (tmpassmap.get(detailass[j].getPk_Checktype()) != null) {
                            OperationResultVO rs = new OperationResultVO();
                            rs.m_intSuccess = 2;
                            rs

                                    .m_strDescription = (new VoucherCheckMessage()).getVoucherMessage(10024) + NCLangResOnserver.getInstance().getStrByID("20021005", "UPP20021005-000580", null, new String[]{String.valueOf(i + 1)}) + detail.getAssid();
                            result = OperationResultVO.appendResultVO(result, new OperationResultVO[]{rs});
                        }
                        tmpassmap.put(detailass[j].getPk_Checktype(), detailass[j]);
                    }
                    Vector<AssVO> tmp_detailass = new Vector();
                    for (int k = 0; k < accass.length; k++) {
                        AccAssVO assVO = accass[k];
                        AssVO tmp_assvo = (AssVO) tmpassmap.get(assVO.getPk_entity());
                        if (tmp_assvo == null || StringUtils.isEmpty(tmp_assvo.getPk_Checkvalue()) || "~"
                                .equals(tmp_assvo.getPk_Checkvalue())) {
                            if (assVO.getIsempty() != null && !assVO.getIsempty().booleanValue() && isCheckEmpty) {
                                OperationResultVO rs = new OperationResultVO();
                                rs.m_intSuccess = 2;
                                rs

                                        .m_strDescription = (new VoucherCheckMessage()).getVoucherMessage(20014) + NCLangResOnserver.getInstance().getStrByID("20021005", "UPP20021005-000575", null, new String[]{String.valueOf(i + 1)});
                                result = OperationResultVO.appendResultVO(result, new OperationResultVO[]{rs});
                                break;
                            }
                            tmp_assvo = new AssVO();
                            tmp_assvo.setPk_Checktype(assVO.getPk_entity());
                            tmp_detailass.addElement(tmp_assvo);
                        } else {
                            tmp_detailass.addElement(tmp_assvo);
                        }
                    }
                }
            }
        return result;
    }

    private OperationResultVO[] checkAssNotNull(VoucherDetailVO detail, int i, OperationResultVO[] result, AccountVO accvo) {
        AccAssVO[] accass = accvo.getAccass();
        OperationResultVO rs = new OperationResultVO();
        if ((accass == null || accass.length <= 0) && detail.getAssid() != null) {
            rs.m_intSuccess = 2;
            rs
                    .m_strDescription = (new VoucherCheckMessage()).getVoucherMessage(10025) + NCLangResOnserver.getInstance().getStrByID("20021005", "UPP20021005-000575", null, new String[]{String.valueOf(i + 1)});
            result = OperationResultVO.appendResultVO(result, new OperationResultVO[]{rs});
        }
        return result;
    }


}